package nz.ac.massey.doi_information_extractor.tests;

import static org.junit.Assert.*;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nz.ac.massey.doi_information_extractor.data.Publication;
import nz.ac.massey.doi_information_extractor.parser.ScienceDirectPlugin;

import org.junit.Before;
import org.junit.Test;

//This class contains rudimentary tests for the ScienceDirectPlugin class. It's based on http://dx.doi.org/10.1016/j.jss.2008.03.060, one of Jen's papers.

public class ScienceDirectPluginTest3 {

	Publication newpub;

	@Before
	public void setUp() throws Exception{
		System.setProperty("http.proxyHost", "tur-cache.massey.ac.nz");
		System.setProperty("http.proxyPort", "8080");
		
		//This is the reason the tests take so long.
		ExecutorService pool = Executors.newFixedThreadPool(1);
		Callable<Publication> scienceDirectPlugin = new ScienceDirectPlugin("10.1016/j.jss.2008.03.060");
		Future<Publication> futureBibsonomyPluginResult = pool.submit(scienceDirectPlugin);

		newpub = futureBibsonomyPluginResult.get();
	}

	@Test
	public void tests() throws Exception{
		
		assertTrue(newpub.getUrl().startsWith("http://www.sciencedirect.com/science?_ob=MImg"));
		
		assertTrue(newpub.getVolumeNumber().equals("81"));
		
		assertTrue(newpub.getEdition().equals("12"));
		
		assertTrue(newpub.getDescription().equals("We present an approach that uses social networking and semantic web technology to share knowledge within the software engineering community. We propose to use existing Web 2.0 services such as social bookmarking and blogs as the infrastructure to share knowledge artefacts. Due to the openness of these services, it is crucial to provide support to establish the trustworthiness of knowledge artefacts. The solution proposed is designed following the original semantic web stack architecture and uses existing and emerging W3C semantic web standards such as the Resource Description Framework (RDF), the Web Ontology Language (OWL), and the Semantic Web Rule Language (SWRL). The WebOfPatterns project is presented as a case study, which includes an Eclipse plug-in that can be used to discover design pattern definitions in social networks, to define and publish patterns, to rate patterns, to establish the trustworthiness of patterns found, and finally to scan Java projects for instances of discovered patter") && (newpub.getDescription().length() <= 1012));
		
		assertTrue(newpub.getDoi().equals("http://dx.doi.org/10.1016/j.jss.2008.03.060"));
		
		assertFalse(newpub.equals(null));
		
		assertTrue(newpub.getArticleTitle().equals("Using social networking and semantic web technology in software engineering &#x2013; Use cases, patterns, and a case study"));
		
		// This should actually be three, but due to ScienceDirect having put an extra link on the end of the string of authors, there's nothing I can do with this plugin to detect that the extra bit isn't an author. 
		assertTrue(newpub.getAuthors().size() == 4);
		
		assertTrue(newpub.getAuthors().get(0).getOrganisation().equals(newpub.getAuthors().get(2).getOrganisation()) && newpub.getAuthors().get(1).getOrganisation().equals("Orion Health, PO Box 8273, Symonds Street, Auckland, New Zealand"));
		
		assertTrue(newpub.getPublicationTitle().equals("Journal of Systems and Software"));
		
		assertTrue(newpub.getPageNumbers().equals("2183-2193"));
		
		assertTrue(newpub.getDate().equals("December 2008"));
	}

}
